package leetcode.code1337;

import java.util.PriorityQueue;

/**
 * 小根堆
 * @author Max
 * @date 2021年8月26日
 * @description
 */
public class Solution extends Solution1337 {

	public class Team {
		public int no;
		public int power;

		Team(int no, int power) {
			this.no = no;
			this.power = power;
		}
	}

	@Override
	public int[] kWeakestRows(int[][] mat, int k) {
		PriorityQueue<Team> p = new PriorityQueue<>((m, n) -> {
			if ((m.power < n.power) || (n.power == m.power && m.no < n.no))
				return -1;
			return 1;
		});
		for (int i = 0; i < mat.length; i++) {
			for (int j = 1; j < mat[0].length; j++) {
				mat[i][0] += mat[i][j];
			}
			p.add(new Team(i, mat[i][0]));
		}
		int[] result = new int[k];
		for (int i = 0; i < k; i++) {
			result[i] = p.poll().no;
		}
		return result;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
	}

}
